/**
 * Copyright &copy; 2012-2014 <a href="https://github.com/thinkgem/jeesite">JeeSite</a> All rights reserved.
 */
package com.thinkgem.jeesite.modules.shop.entity;

import java.util.List;

import javax.validation.constraints.NotNull;

import org.hibernate.validator.constraints.Length;

import com.fasterxml.jackson.annotation.JsonBackReference;
import com.fasterxml.jackson.annotation.JsonIgnore;
import com.google.common.collect.Lists;
import com.thinkgem.jeesite.common.persistence.TreeEntity;

/**
 * 商品分类管理Entity
 * @author xxs
 * @version 2016-03-21
 */
public class GoodsCategory extends TreeEntity<GoodsCategory> {
	
	private static final long serialVersionUID = 1L;
	private GoodsCategory parent;		// 父级编号
	private String parentIds;		// 所有父级编号
	private String name;		// 名称
	private Integer sort;		// 排序
	
	private List<Brand> brandList = Lists.newArrayList(); // 拥有角色列表
	
	@JsonIgnore
	public List<Brand> getBrandList() {
		return brandList;
	}
	
	public void setBrandList(List<Brand> brandList) {
		this.brandList = brandList;
	}

	@JsonIgnore
	public List<String> getBrandIdList() {
		List<String> brandIdList = Lists.newArrayList();
		for (Brand brand : brandList) {
			brandIdList.add(brand.getId());
		}
		return brandIdList;
	}

	public void setBrandIdList(List<String> brandIdList) {
		brandList = Lists.newArrayList();
		for (String brandId : brandIdList) {
			Brand brand = new Brand();
			brand.setId(brandId);
			brandList.add(brand);
		}
	}
	
	public GoodsCategory() {
		super();
	}

	public GoodsCategory(String id){
		super(id);
	}

	@JsonBackReference
	@NotNull(message="父级编号不能为空")
	public GoodsCategory getParent() {
		return parent;
	}

	public void setParent(GoodsCategory parent) {
		this.parent = parent;
	}
	
	@Length(min=1, max=2000, message="所有父级编号长度必须介于 1 和 2000 之间")
	public String getParentIds() {
		return parentIds;
	}

	public void setParentIds(String parentIds) {
		this.parentIds = parentIds;
	}
	
	@Length(min=1, max=100, message="名称长度必须介于 1 和 100 之间")
	public String getName() {
		return name;
	}

	public void setName(String name) {
		this.name = name;
	}
	
	@NotNull(message="排序不能为空")
	public Integer getSort() {
		return sort;
	}

	public void setSort(Integer sort) {
		this.sort = sort;
	}
	
	public String getParentId() {
		return parent != null && parent.getId() != null ? parent.getId() : "0";
	}
}